<%@ page import="java.util.List" %>
<%@ page import="dao.OrderDao" %>
<%@ page import="java.io.PrintWriter" %><%--
  Created by IntelliJ IDEA.
  User: ThinkPad
  Date: 2021/12/26
  Time: 8:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false"%>
<html>
<head>
    <title>后台-销售报表下载</title>
</head>
<body>
<%
    String year = request.getParameter("year");
    String month = request.getParameter("month");
    OrderDao dao = new OrderDao();
    if (month!=null&&!month.equals("0")){
        try {
            List<Object[]> salesList = dao.download(year,month);
            String filename = year+"年"+month+"月销售榜单.csv";
            response.setContentType(application.getMimeType(filename));
            response.setHeader("Content-Disposition","attachment;filename="+new String(filename.getBytes("GBK"),"iso8859-1"));
            response.setCharacterEncoding("gbk");
            PrintWriter pwout = response.getWriter();
            pwout.println("商品名称,销售数量");
            for (Object[] item : salesList) {
                pwout.println(item[0] + "," + item[1]);
            }
            pwout.flush();
            pwout.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
%>
<%@include file="headForRoot.jsp"%>
<br />
<form name="Form1" action="${pageContext.request.contextPath}/download.jsp" method="post">
    <table style="width: 80%;text-align: center;margin-left: 10%">
        <tbody>
        <tr>
            <td style="background-color: #afd1f3">
                <strong>月 度 销 售 榜 单 下 载</strong>
            </td>
        </tr>
        <tr>
            <td>
                <table style="width: 100%">
                    <tr>
                        <td height="22" style="width: 20%;">请输入年份</td>
                        <td style="width: 30%"><label><input type="number" name="year" size="15" value="2021" required/></label></td>
                        <td height="22" style="width: 20%">请选择月份</td>
                        <td style="width: 30%">
                            <label for="month"></label><select name="month" id="month">
                                <option value="0">--选择月份--</option>
                                <option value="1">一月</option>
                                <option value="2">二月</option>
                                <option value="3">三月</option>
                                <option value="4">四月</option>
                                <option value="5">五月</option>
                                <option value="6">六月</option>
                                <option value="7">七月</option>
                                <option value="8">八月</option>
                                <option value="9">九月</option>
                                <option value="10">十月</option>
                                <option value="11">十一月</option>
                                <option value="12">十二月</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td height="22" style="width: 20%"></td>
                        <td style="width: 30%"></td>
                        <td style="width: 20%"><br /><br /></td>
                        <td style="width: 30%">
                            <input type="submit" name="download" value="下载">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="reset" name="reset" value="重置"/>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        </tbody>
    </table>
</form>
<br /><br />
<a href="${pageContext.request.contextPath}/manage.jsp" style="margin-left: 45%;color: blue;font-weight: bold">&lt;返回管理系统主页</a>
<%@include file="tail.jsp"%>
</body>
</html>
